from abc import ABCMeta, abstractmethod
from sqlalchemy.orm import Session

from app.dao.compute import delete_compute_by_service_id


class ComputeDeleter(metaclass=ABCMeta):
    @abstractmethod
    def delete(self):
        pass


class ComputeDeleterImpl(ComputeDeleter):
    service_id: str
    db: Session

    def __init__(self, db: Session, *, service_id: str) -> None:
        super().__init__()

        self.service_id = service_id
        self.db = db

    def _delete_from_db(self):
        delete_compute_by_service_id(self.db, self.service_id)

    def delete(self):
        self._delete_from_db()


def get_compute_deleter(db: Session, *, service_id: str) -> ComputeDeleter:
    return ComputeDeleterImpl(db, service_id=service_id)
